package com.zxl.yjb.im.plugin;

import android.content.Intent;
import android.support.v4.app.Fragment;

import com.zxl.yjb.activity.im.MapLocationActivity;
import io.rong.imkit.RongExtension;
import io.rong.imkit.plugin.DefaultLocationPlugin;
import io.rong.imkit.utilities.PermissionCheckUtil;
/**
 * 介绍 由于项目中高德地图与融云高德地图版本不一样；
 *  所以移除融云自带地图，此处点击打开新版地图的MapLocationActivity；
 * 作者 ssy
 * 时间 2017/5/16
 * 邮箱 1161209667@qq.com
 */
public class LocationPlugin extends DefaultLocationPlugin {
    public void onClick(Fragment currentFragment, RongExtension extension) {
        String[] permissions = new String[]{"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_NETWORK_STATE"};
        if (!PermissionCheckUtil.checkPermissions(currentFragment.getActivity(), permissions)) {
            PermissionCheckUtil.requestPermissions(currentFragment, permissions);
        } else {
            Intent intent = new Intent(currentFragment.getActivity(), MapLocationActivity.class);
            extension.startActivityForPluginResult(intent, 1, this);
        }
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    }
   /* private Conversation.ConversationType conversationType;
    private String targetId;
    @Override
    public Drawable obtainDrawable(Context context) {
        //设置插件 Plugin 图标
        return context.getResources().getDrawable(R.drawable.rc_ext_plugin_location_selector);
    }
    @Override
    public String obtainTitle(Context context) {
        //设置插件 Plugin 展示文字
        return "位置";
    }

    @Override
    public void onClick(Fragment fragment, RongExtension rongExtension) {
        //示例获取 会话类型、targetId、Context,此处可根据产品需求自定义逻辑，如:开启新的 Activity 等。
        conversationType = rongExtension.getConversationType();
        targetId = rongExtension.getTargetId();
        //只有通过 extension 中的 startActivityForPluginResult 才会返回到本类中的 onActivityResult
        rongExtension.startActivityForPluginResult(new Intent(fragment.getActivity(),MapLocationActivity.class),5, this);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null) {
            double latitude = data.getDoubleExtra("latitude",0.00);
            double longitude = data.getDoubleExtra("longitude",0.00);
            String address = data.getStringExtra("address");
            String uri = data.getStringExtra("locuri");
            LocationMessage locationMessage = LocationMessage.obtain(latitude,longitude,address, Uri.parse(uri));
            RongIM.getInstance().sendLocationMessage(Message.obtain(targetId, conversationType, locationMessage), null, null, null);
        }
    }*/
}